<template>
  <div>
    <input placeholder="输入关键字搜索" v-model="text"/>
    <table class="my-table">
      <thead>
        <tr>
          <th>就诊日期</th>
          <th>医生姓名</th>
          <th>诊断结果</th>
          <th>处方信息</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <RenderingData
          v-for="item in renderList"
          :key="item.name"
          :date="item.date"
          :userName="item.userName"
          :symptom="item.symptom"
          :healthy="item.healthy"
          :detail="item.detail"
          :id="item.id"
          @sayPrice="sayPrice"
        ></RenderingData>
      </tbody>
    </table>
    <DetailsPage
      v-show="flag"
      :date="particulars.date"
      :userName="particulars.userName"
      :symptom="particulars.symptom"
      :healthy="particulars.healthy"
      :detail="particulars.detail"
      :id="particulars.id"
      @sayDisplay="sayDisplay"
    ></DetailsPage>
  </div>
</template>
<script>
import RenderingData from './components/RenderingData.vue'
import DetailsPage from './components/DetailsPage.vue'
export default {
  components: {
    RenderingData,
    DetailsPage,
  },
  data() {
    return {
      flag: false,
      text: '',
      particulars: '',
      arr: [
        {
          id: 1,
          date: '2020 - 12 - 12',
          userName: '王同学',
          symptom: '腹痛',
          healthy: '止疼药',
          detail: '详情',
        },
        {
          id: 2,
          date: '2020 - 12 - 12',
          userName: '侯同学',
          symptom: '头疼',
          healthy: '止疼药',
          detail: '详情',
        },
        {
          id: 3,
          date: '2020 - 12 - 12',
          userName: '汪同学',
          symptom: '感冒',
          healthy: '感冒药',
          detail: '详情',
        },
      ],
    }
  },
  methods: {
    sift() {
      this.arr = this.arr.filter((item) => item.userName === this.text)
    },
    sayPrice(id) {
      this.flag = true
      this.particulars = this.arr.find((item) => item.id === id)
    },
    sayDisplay() {
      this.flag = false
    },
  },
  computed: {
    renderList() {
      return this.arr.filter((item) => {
        return (
          item.date.includes(this.text) ||
          item.userName.includes(this.text) ||
          item.symptom.includes(this.text) ||
          item.healthy.includes(this.text)
        )
      })
    },
  },
}
</script>

<style scoped>
.my-table {
  border-collapse: collapse;
  width: 100%;
}

.my-table td,
.my-table th {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: left;
}

.my-table th {
  background-color: #f2f2f2;
}
</style>
